<?php  
//include_once("UserIncludes/DataTables.php");

session_start();
if($_POST['mode']=="login")
{
 	login();
}
function login()
{
$REMEmber=$_REQUEST['RememberMe'];

$username=$_REQUEST['uname'];
$PASSword=$_REQUEST['password'];
	$login_sql="SELECT *  FROM ".SITEUSER." WHERE username='".mysql_escape_string($_REQUEST['uname'])."' AND password='".md5(mysql_escape_string($_REQUEST['password']))."' ";
		$login_rs=mysql_query($login_sql) or die(mysql_error());
		if(mysql_num_rows($login_rs)>0)
		{
				$login_row=mysql_fetch_array($login_rs);
				$_SESSION['siteuserId'] = $login_row['siteuserId'];
				echo $_SESSION['username']=$login_row['username'];
				$_SESSION['fName']=$login_row['fName'];
				$_SESSION['lName']=$login_row['lName'];
				$_SESSION['email']=$login_row['email'];
				$_SESSION['registrationDate']=$login_row['registrationDate'];
				$_SESSION['company']=$login_row['company'];
				$_SESSION['time']=time();

				if(isset($REMEmber)=='Y')
					{							
					setcookie('REMEMBERUSER_NAME',$username,time() + (int)(3*24*3600));
					setcookie('REMEMBERUSER_PASS',$PASSword,time() + (int)(3*24*3600));
					}
				if(isset($REMEmber)=='')
					{					
					setcookie('REMEMBERUSER_NAME','',time()-3*24*3600);
					setcookie('REMEMBERUSER_PASS','',time()-3*24*3600);
					}


			header("Location:index.php");

		}
		else
		{
		 $GLOBALS['msg']="Invalid User Name And Password";
		
		}

}
?>
<form  method="post" action="" id="loginForm">
<input type="hidden" name="mode" value="login" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                      
                      <tr>
                        <td><img src="images/spacer.gif" alt="" width="10" height="7"></td>
                      </tr>
                      <tr>
                        <td><?php
if($_SESSION['siteuserId']!=''){?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td class="LoginBoxTitleBg">Wel Come</td>
                              </tr>
                              <tr>
                                <td class="LoginBoxBg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                  
                                  <tr>
                                    <td><img src="images/spacer.gif" alt="" width="10" height="10"></td>
                                  </tr>
                                  <tr>
                                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          
                                      <tr>
                                        <td height="20" class="BlueBoldcontent"><?php echo $_SESSION['username'];?></td>
                                      </tr>

                                      <tr>
                                        <td align="right"><input name="logout" type="button" class="LoginInputButton" id="button2" value="Logout" onclick="window.location='logout.php'"></td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table>



			<?php } 

			else { ?><table width="100%" border="0" cellpadding="0" cellspacing="0" class="LoginBoxBorder">
                          <tr>
                            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td class="LoginBoxTitleBg">login</td>
                              </tr>
                              <tr>
                                <td class="LoginBoxBg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                  
                                  <tr>
                                    <td><img src="images/spacer.gif" alt="" width="10" height="10"></td>
                                  </tr>
                                  <tr>
                                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td height="20" style="color:#FF0000;font-family: Arial;font-size: 11px;"><?php if($GLOBALS['msg']!=''){ echo $GLOBALS['msg'];} ?></td>
                                      </tr>
                                      <tr>
                                        <td height="20" class="BlueBoldcontent">User id:</td>
                                      </tr>
                                      <tr>
                                        <td height="25"><input name="uname" type="text" class="InputBoxLogin" id="uname" value="<?php echo $_COOKIE['REMEMBERUSER_NAME'];?>" ></td>
                                      </tr>
                                      <tr>
                                        <td height="20" class="BlueBoldcontent">Password:</td>
                                      </tr>
                                      <tr>
                                        <td height="25"><input type="password" class="InputBoxLogin" id="password" name="password" value="<?php echo $_COOKIE['REMEMBERUSER_PASS'];?>"></td>
                                      </tr>
                                      <tr>
                                        <td height="35"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                          <tr>
                                            <td><img src="images/OrangeArrow.gif" alt="" width="4" height="7" align="absmiddle"><input type="checkbox" name="RememberMe" id="RememberMe" value="Y" /><a href="#" class="linkLogin">Remember Me</a></td>
                                            <td width="12">&nbsp;</td>
                                            <td><img src="images/OrangeArrow.gif" alt="" width="4" height="7" align="absmiddle"> <a href="forgetpassword.php" class="linkLogin">Forgot Password</a></td>
                                          </tr>
                                        </table></td>
                                      </tr>
                                      <tr>
                                        <td align="right"><input name="login" type="submit" class="LoginInputButton" id="login" value="Login"></td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table><?php }?></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td><img src="images/spacer.gif" alt="" width="10" height="7"></td>
                      </tr>
                    </table>
		</form>
